//SOLS and FDI
//Bryan Rooney and Matt DiLorenzo
//1.26.2021


use "II_Rooney_DiLo_Rep.dta", clear


global X lag_ln_gdp lag_gdp_growth lag_nat_resources lag_consumption lag_ln_tradegdp lag_ln_pop



	eststo:	glm fdi_gdp lag_fdi_gdp lag_solschange sols_dem lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
	eststo:	glm fdi_gdp lag_fdi_gdp lag_solschange sols_polity polity2 $X i.ccode i.year, cluster(ccode) family(gaussian) link(log)
	eststo:	glm fdi_gdp lag_fdi_gdp lag_solschange sols_vdem vdem $X i.ccode i.year, cluster(ccode) family(gaussian) link(log)
		eststo:	glm fdi_gdp lag_fdi_gdp lag_solschange sols_polcon polconv $X i.ccode i.year if year>=1982 & year<2009, robust family(gaussian) link(log)
		eststo:	glm fdi_gdp lag_fdi_gdp lag_solschange sols_hrv transparencyindex $X i.ccode i.year if year>=1982 & year<2009, robust family(gaussian) link(log)
	estout using "Table_Dem_Full.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		keep(lag_solschange sols_dem lag_dem sols_polity polity2 sols_vdem vdem sols_polcon polconv sols_hrv transparencyindex $X lag_fdi_gdp  _cons) ///
		order(lag_solschange sols_dem lag_dem sols_polity polity2 sols_vdem vdem sols_polcon polconv $X sols_hrv transparencyindex lag_fdi_gdp  _cons) ///
		mgroups("FDI (\% GDP)" "FDI (\% GDP)" "FDI (\% GDP)" "FDI (\% GDP)" "FDI (\% GDP)" , pattern(1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		varlabels(_cons "Constant", elist(_cons)) ///
		mlabels("(1)" "(2)" "(3)" "(4)" "(5)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	

		estimates clear
		
	
		
//Other DV Models

estimates clear
	eststo:	glm nf_invest lag_nf_invest  lag_solschange sols_dem lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
		eststo:	glm bonds_gdp lag_bonds_gdp  lag_solschange sols_dem lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
	estout using "Table_Altdv.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		keep(lag_solschange sols_dem lag_dem $X lag_fdi_gdp lag_nf_invest lag_bonds_gdp _cons) ///
		order(lag_solschange sols_dem lag_dem $X lag_fdi_gdp lag_nf_invest lag_bonds_gdp _cons) ///
		mgroups( "Non-Financial Investment (\% GDP)" "Portfolio Investment in Bonds (\% GDP)", pattern(1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Country and Year Fixed Effects & Yes  \\")) ///
		mlabels("(1)" "(2)")  ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	

		estimates clear

//Alt IV
		
	eststo:	glm fdi_gdp lag_fdi_gdp lag_solschange  sols_dem lag_dem  past_lt $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)	
		eststo:	glm fdi_gdp lag_fdi_gdp lag_lt lt_dem lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
		eststo:	glm fdi_gdp lag_fdi_gdp lag_regtr  regtr_dem lag_dem   $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
		eststo:	glm fdi_gdp lag_fdi_gdp lag_lrc rlc_dem lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
		eststo:	glm fdi_gdp lag_fdi_gdp lag_irreg_2 irreg_dem lag_dem  $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
	estout using "Table_Alt_IV.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		keep(lag_solschange sols_dem lag_lt lt_dem lag_regtr  regtr_dem lag_lrc rlc_dem lag_irreg_2  irreg_dem past_lt lag_dem $X  lag_fdi_gdp  _cons) ///
		order(lag_solschange sols_dem lag_lt lt_dem lag_regtr  regtr_dem lag_lrc rlc_dem  lag_irreg_2 irreg_dem past_lt lag_dem  $X lag_fdi_gdp   _cons) ///
		mgroups("FDI (\% GDP)" "FDI (\% GDP)" "FDI (\% GDP)" "FDI (\% GDP)" "FDI (\% GDP)", pattern(1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Country and Year Fixed Effects & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)" "(4)" "(5)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	

		estimates clear

//Figure 1

	set scheme s1mono
	eststo:	glm fdi_gdp lag_fdi_gdp i.lag_solschange##c.polity2 $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
	margins, dydx(lag_solschange) at( polity2=(-10 (1) 10))
	marginsplot, ytitle("% Change in FDI") xtitle("Polity Score") ///
	title("Change in FDI Across Democracy Level") ///
	ylabel(-.08 "-8" -.06 "-6" -.04 "-4" -.02 "-2" 0 "0"  ,labsize(medium) angle(horizontal) glcolor(gs15) gmax gmin) ///
	xlabel(-10(2)10, labsize(medium)) 
	graph export sols_polity.pdf, replace	
	
		
//Multiple Lags


estimates clear
	eststo:	glm fdi_gdp lag_fdi_gdp L1.lag_fdi_gdp L2.lag_fdi_gdp lag_solschange sols_dem lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
	estout using "Table_Lags.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		keep(lag_solschange sols_dem lag_dem $X *.lag_fdi_gdp _cons) ///
		order(lag_solschange sols_dem lag_dem $X *.lag_fdi_gdp  _cons) ///
		mgroups("FDI (\% GDP)", pattern(1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Country and Year Fixed Effects & Yes  \\")) ///
		mlabels("(1)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	

		estimates clear

//Persistence Test
global X lag_ln_gdp lag_gdp_growth lag_nat_resources lag_consumption lag_ln_tradegdp lag_ln_pop

	sort ccode year

by ccode: gen lp_fdi_gdp = fdi_gdp[_n+1]
by ccode: gen lp2_fdi_gdp = fdi_gdp[_n+2]
by ccode: gen lp3_fdi_gdp = fdi_gdp[_n+3]
by ccode: gen lp4_fdi_gdp = fdi_gdp[_n+4]
by ccode: gen lp5_fdi_gdp = fdi_gdp[_n+5]

		estimates clear


	eststo:	glm lp_fdi_gdp  lag_fdi_gdp lag_solschange sols_dem lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
		eststo:	glm lp2_fdi_gdp  lag_fdi_gdp lag_solschange sols_dem lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
		eststo:	glm lp3_fdi_gdp lag_fdi_gdp lag_solschange sols_dem lag_dem   $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
	estout using "Table_Persistence.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		keep(lag_solschange sols_dem lag_dem  $X  lag_fdi_gdp  _cons) ///
		order(lag_solschange sols_dem lag_dem  $X lag_fdi_gdp   _cons) ///
		mgroups("FDI (\% GDP) t+1" "FDI (\% GDP) t+2" "FDI (\% GDP) t+3", pattern(1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Country and Year Fixed Effects & Yes & Yes & Yes \\")) ///
		mlabels("(1)" "(2)" "(3)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	

		estimates clear
	
//Placebo Test
global X lag_ln_gdp lag_gdp_growth lag_nat_resources lag_consumption lag_ln_tradegdp lag_ln_pop


estimates clear

estimates clear
	eststo:	glm l2_fdi_gdp  lag_solschange sols_dem lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
	estout using "Table_Placebo.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		keep(lag_solschange sols_dem lag_dem $X    _cons) ///
		order(lag_solschange sols_dem lag_dem $X    _cons) ///
		mgroups("FDI (\% GDP) t-2", pattern(1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Country and Year Fixed Effects & Yes  \\")) ///
		mlabels("(1)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	

		estimates clear
		


//Past SOLS Changes


		estimates clear
	eststo:	glm fdi_gdp lag_fdi_gdp lag_solschange  sols_dem lag_dem  past_sc $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
	estout using "Table_PastSOLSControl.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		keep(lag_solschange  sols_dem lag_dem past_sc $X  lag_fdi_gdp  _cons) ///
		order(lag_solschange sols_dem lag_dem past_sc $X lag_fdi_gdp   _cons) ///
		mgroups("FDI (\% GDP)", pattern(1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Country and Year Fixed Effects & Yes  \\")) ///
		mlabels("(1)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	

		estimates clear

//Non SOLS Changes
	
		estimates clear
	eststo:	glm fdi_gdp lag_fdi_gdp non_sols_lt non_sols_lt_dem lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
	estout using "Table_NonSols.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		keep(non_sols_lt non_sols_lt_dem lag_dem $X  lag_fdi_gdp  _cons) ///
		order(non_sols_lt non_sols_lt_dem lag_dem $X lag_fdi_gdp   _cons) ///
		mgroups("FDI (\% GDP)", pattern(1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Country and Year Fixed Effects & Yes  \\")) ///
		mlabels("(1)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	

		estimates clear

// BITs Control


estimates clear
	eststo:	glm fdi_gdp lag_fdi_gdp lag_solschange sols_dem lag_dem $X lag_bit i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
	estout using "Table_BIT_Small.tex", ///
		cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) stats(N, fmt(%9.0f) labels("N")) ///
		eqlabels(none) collabels(none) style(tex) starlevels(* .10 ** .05 *** .01) label ///
		keep(lag_solschange sols_dem lag_dem lag_bit $X lag_fdi_gdp   _cons) ///
		order(lag_solschange sols_dem lag_dem lag_bit $X lag_fdi_gdp   _cons) ///
		mgroups("FDI (\% GDP)", pattern(1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
		varlabels(_cons "Constant", elist(_cons "\addlinespace \hline Country and Year Fixed Effects & Yes  \\")) ///
		mlabels("(1)") ///
		prehead("\resizebox{\textwidth}{!}{" "\begin{tabular}{{l}*{@M}{c}}" "\hline") ///
		posthead(\hline) prefoot(\hline) ///
		postfoot("\hline" "\end{tabular}" "}") replace	

		estimates clear		
		
//Figure H

	eststo:	glm fdi_gdp lag_fdi_gdp i.lag_solschange##i.vdem $X i.ccode i.year, cluster(ccode) family(gaussian) link(log)
		margins, dydx(lag_solschange) at( vdem=(0 1))
	marginsplot, ytitle("% Change in FDI") xtitle("Regime Type") ///
	title("Change in FDI Across Regime Type (RoW)") ///
	ylabel( -.04 "-4" -.02 "-2" 0 "0"  ,labsize(medium) angle(horizontal) glcolor(gs15) gmax gmin) ///
	xlabel(0 "RoW Non-Democracy" 1 "RoW Democracy", labsize(medium)) xsc(r(-.5 1.5))
	graph export sols_vdem.pdf, replace	

	eststo:	glm fdi_gdp lag_fdi_gdp i.lag_solschange##i.lag_dem $X i.ccode i.year if year>=1982 & year<2009, cluster(ccode) family(gaussian) link(log)
margins, dydx(lag_solschange) at( lag_dem=(0 1))
	marginsplot, ytitle("% Change in FDI") xtitle("Regime Type") ///
	title("Change in FDI Across Regime Type") ///
	ylabel( -.04 "-4" -.02 "-2" 0 "0"  ,labsize(medium) angle(horizontal) glcolor(gs15) gmax gmin) ///
	xlabel(0 "Non-Democracy" 1 "Democracy", labsize(medium)) xsc(r(-.5 1.5))
	graph export sols_dem.pdf, replace	

